package com.xak.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xak.dao.StudentMapper;
import com.xak.pojo.entity.Student;
import com.xak.pojo.vo.StudentVo;
import com.xak.service.StudentService;
import com.xak.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @program: springboot0412
 * @description:
 * @author: 肖安康
 * @create: 2023-04-12 19:40
 **/
@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    StudentMapper studentMapper;
    @Override
    public Result findByPage(Integer current, Integer pageSize, StudentVo studentVo) {
        //分页对象
        Page<Student> page = new Page<>(current,pageSize);
        //条件
        QueryWrapper<Student> wrapper = new QueryWrapper<>();
        //判断名称是否为空
        if (StringUtils.hasText(studentVo.getName())){
            wrapper.like("sname",studentVo.getName());
        }
        //根据年龄
        if (studentVo.getAge()!=null){
            wrapper.ge("sage",studentVo.getAge());
        }
       studentMapper.findPage(page, null);
        //公共对象---封装到Page对象中---
        return new Result(200,"分页查询成功",page);
    }
}
